package com.migo.service.impl;

import com.migo.dao.UserDao;
import com.migo.entity.UserEntity;
import com.migo.service.UserService;
import com.migo.utils.DateUtils;
import com.migo.utils.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("userService")
public class UserServiceImpl implements UserService {
	@Autowired
	private UserDao userDao;
	
	@Override
	public UserEntity queryObject(Integer id){
		return userDao.queryObject(id);
	}
	
	@Override
	public List<UserEntity> queryList(Map<String, Object> map){
		return userDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return userDao.queryTotal(map);
	}
	
	@Override
	public void save(UserEntity user){
		userDao.save(user);
	}
	
	@Override
	public void update(UserEntity user){
		userDao.update(user);
	}
	
	@Override
	public void delete(Integer id){
		userDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Integer[] ids){
		userDao.deleteBatch(ids);
	}

	@Override
	public UserEntity phoneLogin(Map<String, String> map) {
		return userDao.phoneLogin(map);
	}

	@Override
	public UserEntity emailLogin(Map<String, String> map) {
		return userDao.emailLogin(map);
	}

	@Override
	public void modiyPassword(String userId, String newPassword) {
		userDao.modiyPassword(userId,newPassword);
	}

	@Override
	public UserEntity queryUser(String userId) {
		return userDao.queryUser(userId);
	}

	@Override
	public UserEntity queryUserExist(Map<String, String> map) {
		return userDao.queryUserExist(map);
	}

	@Override
	public void register(Map<String, String> params) {
		String password = params.get("password");
		//sha256加密
//		password = new Sha256Hash(password).toHex();
		//保留version+ 第一版需求
		password = MD5.encrypt(password);
		String nickname = params.get("nickname");
		String country = params.get("country");
		String email = params.get("email");
		String mobile = params.get("mobile");
		String uuid = params.get("uuid");
		String ip = params.get("ip");
		String deviceType = params.get("deviceType");
		UserEntity eUser = new UserEntity();
		eUser.setUseremail(email);
		eUser.setDeviceType(deviceType);
		eUser.setPassword(password);
		eUser.setNickname(nickname);
		eUser.setCountry(country);
		eUser.setUserphone(mobile);
		eUser.setUserReqIp(ip);
		eUser.setUserId(uuid);
		eUser.setAddtime(DateUtils.getNow());
		userDao.register(eUser);
	}

}
